package com.dream.wukong.common.core.swagger2;

import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 10:51 2018/9/19.
 * @Modified:
 */
@Configuration
//@EnableWebMvc
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket addUserDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(Lists.newArrayList(apiKey()));
    }

    /**
     * apiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring boot swagger Document API")
                .description(" API Document管理")
                .version("V1.0.0")
                .termsOfServiceUrl("")
                .license("")
                .licenseUrl("")
                .termsOfServiceUrl("www.wukong.com")
                .build();
    }

    /**
     * apiKey
     */
    private ApiKey apiKey() {
        return new ApiKey("Authorization", "Authorization", "header");
    }
}